/**
 * machine-list 
 * require and vue eg:http://www.cnblogs.com/taoquns/p/5960415zds.html
 */
//头部个人中心
require.config({
	shim:{
        'echarts':{exports:'echarts'},
        'calendar':{exports:'calendar'},
        'swiper':{exports:'swiper'}
    },
    paths : {
        "jquery":"lib/jquery",
        'echarts':'lib/echarts.common.min',
        "cmd":"cmd",
        "calendar":"lib/datepicker/WdatePicker",
        "swiper":"lib/swiper.min"
    }
});
require(['echarts','jquery','cmd','calendar','swiper'],function(echarts,$){
var token = detectToken();
var dtuID = window.location.search.split("=")[1];

//======================================================================
//====================设备详情-上方地图右侧信息START====================
$.ajax({ 
    type:"post", 
    url:urls.getDeviceInfo, 
    data: {token:token,dtu_id:dtuID}, 
    dataType: 'json', 
    async : true,
    success:function(result){
        if(result.code==1){
            $(".getDeviceInfo_1").html(result.data.device_no);
            $(".getDeviceInfo_2").html(result.data.device_name);
            $(".getDeviceInfo_3").html(result.data.power);
            $(".getDeviceInfo_4").html(result.data.sim_no);
            $(".getDeviceInfo_5").html(result.data.customer_name);
            $(".getDeviceInfo_6").html(result.data.dtu_id);
            $(".getDeviceInfo_7").html(result.data.typeName);
            $(".getDeviceInfo_8").html(result.data.industry);
            $(".getDeviceInfo_9").html(result.data.area);
            $(".getDeviceInfo_10").html(result.data.remark);
            $(".getDeviceInfo_11").html(result.data.userName);
            $(".getDeviceInfo_12").html(result.data.create_date);
            $("#switch_zd").attr("data-isConnected",result.data.is_connected);//is_connected:1 online/0 disonline
            //默认加载显示设备定位地图START
                function initMap(){
                    createMap();
                    setMapEvent();
                    addMapControl();
                    addMarker();
                }

                function createMap(){
                    var map = new BMap.Map("dituContent");//sometimes not normal
                    var point = new BMap.Point(result.data.dtu_lng,result.data.dtu_lat);
                    map.centerAndZoom(point,5);
                    window.map = map;
                }

                function setMapEvent(){
                    map.enableDragging();
                    map.enableScrollWheelZoom();
                    map.enableDoubleClickZoom();
                    map.enableKeyboard();
                }

                function addMapControl(){
                    
                    var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
                    map.addControl(ctrl_nav);

                    var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
                    map.addControl(ctrl_sca);
                }

                var markerArr = [{title:result.data.customer_name,content:result.data.device_no,point:result.data.dtu_lng+'|'+result.data.dtu_lat,isOpen:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5}}];

                function addMarker(){
                    for(var i=0;i<markerArr.length;i++){
                        var json = markerArr[i];
                        var p0 = json.point.split("|")[0];
                        var p1 = json.point.split("|")[1];
                        var point = new BMap.Point(p0,p1);
                        var iconImg = createIcon(json.icon);
                        var marker = new BMap.Marker(point,{icon:iconImg});
                        var iw = createInfoWindow(i);
                        var label = new BMap.Label(json.title,{"offset":new BMap.Size(json.icon.lb-json.icon.x+10,-20)});
                        marker.setLabel(label);
                        map.addOverlay(marker);
                        label.setStyle({
                        borderColor:"#808080",
                        color:"#333",
                        cursor:"pointer"
                        });
                        (function(){
                                var index = i;
                                var _iw = createInfoWindow(i);
                                var _marker = marker;
                            _marker.addEventListener("click",function(){
                                this.openInfoWindow(_iw);
                            });
                            _iw.addEventListener("open",function(){
                                _marker.getLabel().hide();
                            })
                            _iw.addEventListener("close",function(){
                                _marker.getLabel().show();
                            })
                            label.addEventListener("click",function(){
                                _marker.openInfoWindow(_iw);
                            })
                            if(!!json.isOpen){
                                label.hide();
                                _marker.openInfoWindow(_iw);
                            }
                        })()
                    }
                }

                    function createInfoWindow(i){
                        var json = markerArr[i];
                        var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>"+json.content+"</div>");
                        return iw;
                    }

                    function createIcon(json){
                        var icon = new BMap.Icon("http://map.baidu.com/image/us_cursor.gif", new BMap.Size(json.w,json.h),{imageOffset: new BMap.Size(-json.l,-json.t),infoWindowOffset:new BMap.Size(json.lb+5,1),offset:new BMap.Size(json.x,json.h)})
                        return icon;
                    }
                    initMap();
                    $(".anchorBL").hide();
            //默认加载显示设备地位地图END

            //点击定位--设备修改定位
            $(".getDeviceInfo_5,.i-located").click(function(){
                $(".dituLayerBox,.masking").fadeIn();
                //============地图1START
                /*var map = new BMap.Map("MapLayerbox");
                var point = new BMap.Point(result.data.dtu_lng,result.data.dtu_lng.dtu_lat);
                map.centerAndZoom(point,12);
                map.addEventListener("click", function(e){ //鼠标点击事件
                    var pt = e.point;
                    alert(pt.lng + "xxx" + pt.lat)//弹窗经纬度
                });*/
                //===========地图1END 
                
                //===========地图2START
                function initMap(){
                    createMap();
                    setMapEvent();
                    addMapControl();
                    addMarker();
                }

                function createMap(){
                    var map = new BMap.Map("MapLayerbox");
                    var point = new BMap.Point(result.data.dtu_lng,result.data.dtu_lat);
                    map.centerAndZoom(point,5);
                    map.addEventListener("click", function(e){ //鼠标点击事件
                    var pt = e.point;
                        var conf = confirm("经度："+pt.lng+"   "+"纬度："+ pt.lat);
                        if(conf){
                            $.vloading.show();
                            $.ajax({ 
                                type:"post", 
                                url:urls.setDeviceslocation, 
                                data: {token:token,dtu_id:dtuID,dtu_lng:pt.lng,dtu_lat:pt.lat}, 
                                dataType: 'json', 
                                async : true,
                                success:function(result){ 
                                    $.vloading.remove();
                                    if(result.code==1){
                                        $.flytip(result.msg);
                                        setTimeout('window.location.reload()',1000);
                                    }else{
                                        $.flytip(result.msg);
                                    }

                                } 
                            });
                        }
                    });
                    window.map = map;
                }

                function setMapEvent(){
                    map.enableDragging();
                    map.enableScrollWheelZoom();
                    map.enableDoubleClickZoom();
                    map.enableKeyboard();
                }

                function addMapControl(){
                    
                    var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
                    map.addControl(ctrl_nav);

                    var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
                    map.addControl(ctrl_sca);
                }

                var markerArr = [{title:result.data.customer_name,content:result.data.device_no,point:result.data.dtu_lng+'|'+result.data.dtu_lat,isOpen:0,icon:{w:21,h:21,l:0,t:0,x:6,lb:5}}];

                function addMarker(){
                    for(var i=0;i<markerArr.length;i++){
                        var json = markerArr[i];
                        var p0 = json.point.split("|")[0];
                        var p1 = json.point.split("|")[1];
                        var point = new BMap.Point(p0,p1);
                        var iconImg = createIcon(json.icon);
                        var marker = new BMap.Marker(point,{icon:iconImg});
                        var iw = createInfoWindow(i);
                        var label = new BMap.Label(json.title,{"offset":new BMap.Size(json.icon.lb-json.icon.x+10,-20)});
                        marker.setLabel(label);
                        map.addOverlay(marker);
                        label.setStyle({
                        borderColor:"#808080",
                        color:"#333333",
                        cursor:"pointer"
                        });
                        (function(){
                                var index = i;
                                var _iw = createInfoWindow(i);
                                var _marker = marker;
                            _marker.addEventListener("click",function(){
                                this.openInfoWindow(_iw);
                            });
                            _iw.addEventListener("open",function(){
                                _marker.getLabel().hide();
                            })
                            _iw.addEventListener("close",function(){
                                _marker.getLabel().show();
                            })
                            label.addEventListener("click",function(){
                                _marker.openInfoWindow(_iw);
                            })
                            if(!!json.isOpen){
                                label.hide();
                                _marker.openInfoWindow(_iw);
                            }
                        })()
                    }
                }

                    function createInfoWindow(i){
                        var json = markerArr[i];
                        var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>"+json.content+"</div>");
                        return iw;
                    }

                    function createIcon(json){
                        var icon = new BMap.Icon("http://map.baidu.com/image/us_cursor.gif", new BMap.Size(json.w,json.h),{imageOffset: new BMap.Size(-json.l,-json.t),infoWindowOffset:new BMap.Size(json.lb+5,1),offset:new BMap.Size(json.x,json.h)})
                        return icon;
                    }
                    initMap();
                    $(".anchorBL").hide();
                //===========地图2END 

            })
        }else{
            $.flytip(result.msg);
        } 
    } 
});
//================================================================
//====================设备详情-地图右侧信息END====================


//======================================================================
//====================设备详情-图表最新记录START========================
//=========注：实时监控功能只能针对最新记录数据进行监控，历史数据不可以
var getLatestRecording = function(api,date){
    $.ajax({ 
        type:"post", 
        //url:urls.getNewestDevicedetils,
        url:api, 
        data: {token:token,dtu_id:dtuID,date:date},
        dataType: 'json', 
        async : true,
        success:function(result){
            if(result.code==1){
                var getZhongwenParams = function(m){
                    var paramsEnglish = [];//英文key
                    var paramsChinese = [];//中文key
                    for(var i=0;i<result.data[m][0].length;i++){
                        if(result.data[m][0][i]!="create_date"){
                            paramsEnglish.push(result.data[m][0][i]);
                        }
                    }
                      $.ajax({ 
                        type:"post", 
                        url:urls.getKeynames, 
                        data: {token:token,keys:paramsEnglish.join(",")}, 
                        dataType: 'json', 
                        async : false,
                        success:function(result){ 
                            if(result.code==1){
                                for(var i=0;i<result.data.length;i++){
                                    if(result.data[i]==null){
                                        paramsChinese.push("wtParams");
                                    }else{
                                        paramsChinese.push(result.data[i]);
                                    }
                                }
                                
                            }else{
                                $.flytip(result.msg);
                            }
                        } 
                    });
                    return paramsChinese;                        
            }

            var getZhengjiAllParams = function(m){
                        var allNeedParamsDatas_Obj = {};//Devices all need params literal object
                        var returnParams_Nums = result.data[m][0].length;//all parameters returned
                        var timerPointsArr = result.data[m][1][returnParams_Nums-1];//timer
                        switch (returnParams_Nums)
                        {
                        case 2:
                          allNeedParamsDatas=[
                                                {name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]}
                                            ];
                          break;
                        case 3:
                          allNeedParamsDatas=[
                                                {name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]
                                                },{name:zhengji_ParamsChinese[1],type:'line',stack: 'total',data:result.data[m][1][1]}
                                            ];
                          break;
                        case 4:
                          allNeedParamsDatas=[
                                                {name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]
                                                },{name:zhengji_ParamsChinese[1],type:'line',stack: 'total',data:result.data[m][1][1]
                                                },{name:zhengji_ParamsChinese[2],type:'line',stack: 'total',data:result.data[m][1][2]}
                                            ];
                          break;
                        case 5:
                          allNeedParamsDatas=[
                                                {name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]
                                                },{name:zhengji_ParamsChinese[1],type:'line',stack: 'total',data:result.data[m][1][1]
                                                },{name:zhengji_ParamsChinese[2],type:'line',stack: 'total',data:result.data[m][1][2]
                                                },{name:zhengji_ParamsChinese[3],type:'line',stack: 'total',data:result.data[m][1][3]}
                                            ];
                          break;
                        case 6:
                          allNeedParamsDatas=[
                                                {name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]
                                                },{name:zhengji_ParamsChinese[1],type:'line',stack: 'total',data:result.data[m][1][1]
                                                },{name:zhengji_ParamsChinese[2],type:'line',stack: 'total',data:result.data[m][1][2]
                                                },{name:zhengji_ParamsChinese[3],type:'line',stack: 'total',data:result.data[m][1][3]
                                                },{name:zhengji_ParamsChinese[4],type:'line',stack: 'total',data:result.data[m][1][4]}
                                            ];
                          break;
                        case 7:
                          allNeedParamsDatas=[
                                                {name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]
                                                },{name:zhengji_ParamsChinese[1],type:'line',stack: 'total',data:result.data[m][1][1]
                                                },{name:zhengji_ParamsChinese[2],type:'line',stack: 'total',data:result.data[m][1][2]
                                                },{name:zhengji_ParamsChinese[3],type:'line',stack: 'total',data:result.data[m][1][3]
                                                },{name:zhengji_ParamsChinese[4],type:'line',stack: 'total',data:result.data[m][1][4]
                                                },{name:zhengji_ParamsChinese[5],type:'line',stack: 'total',data:result.data[m][1][5]}
                                            ];
                          break;
                        case 8:
                          allNeedParamsDatas=[
                                                {name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]
                                                },{name:zhengji_ParamsChinese[1],type:'line',stack: 'total',data:result.data[m][1][1]
                                                },{name:zhengji_ParamsChinese[2],type:'line',stack: 'total',data:result.data[m][1][2]
                                                },{name:zhengji_ParamsChinese[3],type:'line',stack: 'total',data:result.data[m][1][3]
                                                },{name:zhengji_ParamsChinese[4],type:'line',stack: 'total',data:result.data[m][1][4]
                                                },{name:zhengji_ParamsChinese[5],type:'line',stack: 'total',data:result.data[m][1][5]
                                                },{name:zhengji_ParamsChinese[6],type:'line',stack: 'total',data:result.data[m][1][6]}
                                            ];
                          break;
                        case 1:
                          allNeedParamsDatas=[{name:zhengji_ParamsChinese[0],type:'line',stack: 'total',data:result.data[m][1][0]}];
                          break;
                        default:
                          $.flytip("params return error!");
                        }
                        
                        return allNeedParamsDatas_Obj = {
                            allNeedParamsDatas:allNeedParamsDatas,
                            timerPointsArr:timerPointsArr
                        }
                        
                }

                //===================整机参数图表START===================
                //=======================================================
                if(typeof(result.data[10])!="undefined"){//整机参数若存在
                    //===============================
                    //======整机参数chart--start=====
                    $("#mainChart10").show();
                    var zhengji_ParamsChinese = getZhongwenParams(10);
                    var allParamsListValue = getZhengjiAllParams(10);
                    var myChart10 = echarts.init(document.getElementById('mainChart10'));
                    var option10 = {
                        title: {
                            text: '整机',
                            x: 'left',
                            y:'top',
                            itemGap: 12,
                            textStyle: {fontSize: 12,align:'left',color: '#79797a',fontWeight:'normal'},
                            subtextStyle: {color: '#797979',align:'left',fontSize:11}
                        },
                        tooltip: {trigger: 'axis'},
                        legend: {
                            orient: 'vertical',
                            data:zhengji_ParamsChinese,
                            x: 'right',
                            y: 'top',
                            textStyle:{color:'#9b9b9b'}
                        },
                        grid: {x2: 160,x:20},
                        toolbox: {feature: {saveAsImage: {show : false}}},
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: allParamsListValue.timerPointsArr,
                            axisLabel:{
                                  rotate:0, //rotate 45
                                  textStyle:{
                                     color:"#333",
                                     fontSize:8
                                }
                              }
                        },
                        yAxis: {show:false,type: 'value'},
                        series: allParamsListValue.allNeedParamsDatas
                    };
                     myChart10.setOption(option10);
                    //===============================
                    //======整机参数chart--end=======
                    
                }else{  
                    //console.log("echart zhengji is none");
                }
                //=======================================================
                //===================整机参数图表END=====================

                //===================主机(1)参数图标START==================
                //=========================================================
                if(typeof(result.data[1])!="undefined"){//主机1若存在
                    //================================
                    //======主机1参数chart--start=====
                    $("#mainChart1").show();
                    var zhengji_ParamsChinese = getZhongwenParams(1);
                    var allParamsListValue = getZhengjiAllParams(1);
                    var myChart1 = echarts.init(document.getElementById('mainChart1'));
                    var option1 = {
                        title: {
                            text: '主机',
                            x: 'left',
                            y:'top',
                            itemGap: 12,
                            textStyle: {fontSize: 12,align:'left',color: '#79797a',fontWeight:'normal'},
                            subtextStyle: {color: '#797979',align:'left',fontSize:11}
                        },
                        tooltip: {trigger: 'axis'},
                        legend: {
                            orient: 'vertical',
                            data:zhengji_ParamsChinese,
                            x: 'right',
                            y: 'top',
                            textStyle:{color:'#9b9b9b'}
                        },
                        grid: {x2: 160,x:20},
                        toolbox: {feature: {saveAsImage: {show : false}}},
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: allParamsListValue.timerPointsArr,
                            axisLabel:{
                                  rotate:0, //rotate 45
                                  textStyle:{
                                     color:"#333",
                                     fontSize:8
                                }
                              }
                        },
                        yAxis: {show:false,type: 'value'},
                        series: allParamsListValue.allNeedParamsDatas
                    };
                     myChart1.setOption(option1);
                    //================================
                    //======主机1参数chart--end=======
                }else{
                    //console.log("echart zhu_ji1 is none");
                }if(typeof(result.data[2])!="undefined"){//主机2若存在
                    //================================
                    //======主机2参数chart--start=====
                    $("#mainChart2").show();
                    var zhengji_ParamsChinese = getZhongwenParams(2);
                    var allParamsListValue = getZhengjiAllParams(2);
                    var myChart2 = echarts.init(document.getElementById('mainChart2'));
                    var option2 = {
                        title: {
                            text: '主机',
                            x: 'left',
                            y:'top',
                            itemGap: 12,
                            textStyle: {fontSize: 12,align:'left',color: '#79797a',fontWeight:'normal'},
                            subtextStyle: {color: '#797979',align:'left',fontSize:11}
                        },
                        tooltip: {trigger: 'axis'},
                        legend: {
                            orient: 'vertical',
                            data:zhengji_ParamsChinese,
                            x: 'right',
                            y: 'top',
                            textStyle:{color:'#9b9b9b'}
                        },
                        grid: {x2: 160,x:20},
                        toolbox: {feature: {saveAsImage: {show : false}}},
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: allParamsListValue.timerPointsArr,
                            axisLabel:{
                                  rotate:0, //rotate 45
                                  textStyle:{
                                     color:"#333",
                                     fontSize:8
                                }
                              }
                        },
                        yAxis: {show:false,type: 'value'},
                        series: allParamsListValue.allNeedParamsDatas
                    };
                     myChart2.setOption(option2);
                    //================================
                    //======主机2参数chart--end=======
                }else{
                    //console.log("echart zhu_ji2 is none");
                }if(typeof(result.data[3])!="undefined"){//风机1若存在
                    //================================
                    //======风机1参数chart--start=====
                    $("#mainChart3").show();
                    var zhengji_ParamsChinese = getZhongwenParams(3);
                    var allParamsListValue = getZhengjiAllParams(3);
                    var myChart3 = echarts.init(document.getElementById('mainChart3'));
                    var option3 = {
                        title: {
                            text: '风机',
                            x: 'left',
                            y:'top',
                            itemGap: 12,
                            textStyle: {fontSize: 12,align:'left',color: '#79797a',fontWeight:'normal'},
                            subtextStyle: {color: '#797979',align:'left',fontSize:11}
                        },
                        tooltip: {trigger: 'axis'},
                        legend: {
                            orient: 'vertical',
                            data:zhengji_ParamsChinese,
                            x: 'right',
                            y: 'top',
                            textStyle:{color:'#9b9b9b'}
                        },
                        grid: {x2: 160,x:20},
                        toolbox: {feature: {saveAsImage: {show : false}}},
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: allParamsListValue.timerPointsArr,
                            axisLabel:{
                                  rotate:0, //rotate 45
                                  textStyle:{
                                     color:"#333",
                                     fontSize:8
                                }
                              }
                        },
                        yAxis: {show:false,type: 'value'},
                        series: allParamsListValue.allNeedParamsDatas
                    };
                     myChart3.setOption(option3);
                    //================================
                    //======主机2参数chart--end=======
                }else{
                    //console.log("echart feng_ji1 is none");
                }if(typeof(result.data[4])!="undefined"){//风机2若存在
                    //================================
                    //======风机1参数chart--start=====
                    $("#mainChart4").show();
                    var zhengji_ParamsChinese = getZhongwenParams(4);
                    var allParamsListValue = getZhengjiAllParams(4);
                    var myChart4 = echarts.init(document.getElementById('mainChart4'));
                    var option4 = {
                        title: {
                            text: '风机',
                            x: 'left',
                            y:'top',
                            itemGap: 12,
                            textStyle: {fontSize: 12,align:'left',color: '#7b7b7b',fontWeight:'normal'},
                            subtextStyle: {color: '#797979',align:'left',fontSize:11}
                        },
                        tooltip: {trigger: 'axis'},
                        legend: {
                            orient: 'vertical',
                            data:zhengji_ParamsChinese,
                            x: 'right',
                            y: 'top',
                            textStyle:{color:'#9b9b9b'}
                        },
                        grid: {x2: 160,x:20},
                        toolbox: {feature: {saveAsImage: {show : false}}},
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: allParamsListValue.timerPointsArr,
                            axisLabel:{
                                  rotate:0, //rotate 45
                                  textStyle:{
                                     color:"#333",
                                     fontSize:8
                                }
                              }
                        },
                        yAxis: {show:false,type: 'value'},
                        series: allParamsListValue.allNeedParamsDatas
                    };
                     myChart4.setOption(option4);
                    //================================
                    //======风机2参数chart--end=======
                }else{
                    //console.log("echart feng_ji2 is none");
                }
                //=========================================================
                //===================主机(1)参数图标END====================
            }else{
               $.flytip(result.msg);
            }
            
        } 
    });
}
getLatestRecording(urls.getNewestDevicedetils);
//======================================================================
//====================设备详情-图表最新记录END==========================

//================================================================
//====================获取设备运行参数START=======================
var getWorkingParams = function(){
    $.ajax({ 
        type:"post", 
        url:urls.getDeviceRunParams, 
        data: {token:token,dtu_id:dtuID},
        dataType: 'json', 
        async : true,
        success:function(result){
            if(result.code==1){
                //======整机参数START======
                //状态
                var zj_zhuangtai = result.data.machine_status;
                switch(zj_zhuangtai)
                {
                case 0://"0": "机器停止",
                  $(".zj_zhuangtai").html("机器停止");
                  break;
                case 1://"1": "加载延时中",
                  $(".zj_zhuangtai").html("机器报警");
                  break;
                case 2://"2": "加载运行中",
                  $(".zj_zhuangtai").html("加载延时").css("color","#78c26d");
                  break;
                case 3://"3": "空载运行中",
                  $(".zj_zhuangtai").html("加载运行");
                  break;
                case 4://"4": "空久休眠中",
                  $(".zj_zhuangtai").html("空载运行");
                  break;
                case 5://"5": "停机延时中"
                  $(".zj_zhuangtai").html("空久休眠");
                  break;                
                case 6://"5": "停机延时中"
                  $(".zj_zhuangtai").html("停机延时");
                  break;                
                case 7://"5": "停机延时中"
                  $(".zj_zhuangtai").html("星角延时");
                  break;
                }
                //信号强度
                $(".zj_xinhao").html(result.data.signal_quality);
                //电源电压
                $(".zj_dianya").html(result.data.dydy);
                //负载时长
                $(".zj_fuzaiTime").html(result.data.load_time);
                //运行时长
                $(".zj_yunxingTime").html(result.data.machine_time);
                //负载率
                var l_time = parseInt(result.data.load_time.split("H")[0]);
                var m_time = parseInt(result.data.machine_time.split("H")[0]);
                if(result.data.load_time==""||result.data.machine_time==""){
                    result.data.load_time=0;
                    result.data.machine_time=0;
                    $(".zj_fuzailv").html("0");
                }else{
                    $(".zj_fuzailv").html(result.data.loadPercent);
                }
                //整机压力
                zhengji_pressure = result.data.pressure;
                if(result.data.pressure==null||typeof(result.data.pressure)=="undefined"||result.data.pressure==""){
                    zhengji_pressure = 0;

                }
                //整机温度
                zhengji_temperature = result.data.temperature;
                if(result.data.temperature==null||typeof(result.data.temperature)=="undefined"||result.data.temperature==""){
                    zhengji_temperature = 0;

                }
                if(result.data.temperature<0){
                    zhengji_temperature = -result.data.temperature;
                    fu_temperature = 1;
                }
                //======整机参数END======

                //=========封装根据key值查询key值字段中文，并且遍历属性值模块方法START=========
                    var get_key_value = function(q){
                        var keysArr = [];//字段英文
                        var keysValArr = [];//字段值
                        var keysCHN_Arr = [];//字段中文
                        for(var val in result.data.equip[q]){
                            //alert( val+"="+result.data.equip[1][val]);
                            keysArr.push(val);
                            keysValArr.push(result.data.equip[q][val]);
                        }
                        //根据key列表获取属性值列表
                        $.ajax({ 
                            type:"post", 
                            url:urls.getKeynames, 
                            data: {token:token,keys:keysArr.join(",")}, 
                            dataType: 'json', 
                            async : true,
                            success:function(result){
                                if(result.code==1){
                                    var getdetailsIndsrHtml = '';
                                    switch (q)
                                    {
                                    case 1:
                                       for(var i=0;i<result.data.length;i++){
                                            keysCHN_Arr.push(result.data[i]);
                                            getdetailsIndsrHtml += '<p><em>'+keysCHN_Arr[i]+'</em><span class="zhuji1_scpl">'+keysValArr[i]+'</span></p>';
                                             
                                        }
                                        $(".detailsInds-r_1").html(getdetailsIndsrHtml);
                                      break;
                                    case 2:
                                       for(var i=0;i<result.data.length;i++){
                                            keysCHN_Arr.push(result.data[i]);
                                            getdetailsIndsrHtml += '<p><em>'+keysCHN_Arr[i]+'</em><span class="zhuji1_scpl">'+keysValArr[i]+'</span></p>';
                                        }
                                        $(".detailsInds-r_2").html(getdetailsIndsrHtml);
                                      break;
                                    case 3:
                                       for(var i=0;i<result.data.length;i++){
                                            keysCHN_Arr.push(result.data[i]);
                                            getdetailsIndsrHtml += '<p><em>'+keysCHN_Arr[i]+'</em><span class="zhuji1_scpl">'+keysValArr[i]+'</span></p>'; 
                                        }
                                        $(".detailsInds-r_3").html(getdetailsIndsrHtml);
                                      break;
                                    case 4:
                                       for(var i=0;i<result.data.length;i++){
                                            keysCHN_Arr.push(result.data[i]);
                                            getdetailsIndsrHtml += '<p><em>'+keysCHN_Arr[i]+'</em><span class="zhuji1_scpl">'+keysValArr[i]+'</span></p>';
                                        }
                                        $(".detailsInds-r_4").html(getdetailsIndsrHtml);
                                      break;
                                    }

                                    //$.flytip(result.msg);
                                }else{
                                    $.flytip(result.msg);
                                }
                            } 
                        });
                    }
                    //=========封装根据key值查询key值字段中文，并且遍历属性值模块方法END=========

                
                //======主机1START======
                if(typeof(result.data.equip[1])!="undefined"){
                   
                    get_key_value(1);
                    $(".zhujiA_workParamsbox").show();
                    //主机1压力环START
                    var myChartA = echarts.init(document.getElementById('ringboxPieA'));
                    var zhuji1_pressure = zhengji_pressure;
                    var percentA = zhuji1_pressure/2;//主机压力百分比计算

                    var dataStyle = {
                        normal: {
                            label: {show:false},
                            labelLine: {show:false}
                        }
                    };
                    var optionA = {
                        backgroundColor: 'rgba(0,0,0,0)',
                        title: {
                            //text: (percent * 100) + '%',
                            text: zhuji1_pressure,
                            subtext: 'Mpa',
                            x: 'center',
                            y: '26%',
                            textStyle: {
                                color: '#596679',
                                fontSize: 18,
                                fontWeight: 'normal'
                            },
                            subtextStyle: {
                                color: '#666',
                                fontSize: 12
                            }
                        },

                        series : [

                            {
                                name: 'main',
                                type: 'pie',
                                radius: [29, 39],
                                hoverAnimation: false,
                                label: {
                                    normal: {
                                        show: false
                                    }
                                },

                                data: getDataA()
                            }

                        ]
                    };

                    function getDataA() {
                        return [{
                            value: percentA,
                            itemStyle:{
                                normal:{
                                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: '#7388d7'
                                    }, {
                                        offset: 1,
                                        color: '#d12977'
                                    }])
                                }
                            }
                        }, {
                            value: 1 - percentA,
                            itemStyle: {
                                normal: {
                                    color: 'transparent'
                                }
                            }
                        }];
                    };
                    myChartA.setOption(optionA);
                    //主机1压力环END
                }else{
                    //console.log("zhu_ji1 is none");
                }

                //======主机1END======
                
                //======主机2START======
                if(typeof(result.data.equip[2])!="undefined"){
                    get_key_value(2);
                    $(".zhujiB_workParamsbox").show();
                    //主机2压力环START
                    var myChartB = echarts.init(document.getElementById('ringboxPieB'));
                    var zhuji2_pressure = zhengji_pressure;
                    var percentB = zhuji2_pressure/2.0;//主机压力百分比计算
                    var dataStyle = {
                        normal: {
                            label: {show:false},
                            labelLine: {show:false}
                        }
                    };
                    var optionB = {
                        backgroundColor: 'rgba(0,0,0,0)',
                        title: {
                            //text: (percent * 100) + '%',
                            text: zhuji2_pressure,
                            subtext: 'Mpa',
                            x: 'center',
                            y: '26%',
                            textStyle: {
                                color: '#596679',
                                fontSize: 18,
                                fontWeight: 'normal'
                            },
                            subtextStyle: {
                                color: '#666',
                                fontSize: 12
                            }
                        },

                        series : [

                            {
                                name: 'main',
                                type: 'pie',
                                radius: [29, 39],
                                hoverAnimation: false,
                                label: {
                                    normal: {
                                        show: false
                                    }
                                },

                                data: getDataB()
                            }

                        ]
                    };

                    function getDataB() {
                        return [{
                            value: percentB,
                            itemStyle:{
                                normal:{
                                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: '#7388d7'
                                    }, {
                                        offset: 1,
                                        color: '#d12977'
                                    }])
                                }
                            }
                        }, {
                            value: 1 - percentB,
                            itemStyle: {
                                normal: {
                                    color: 'transparent'
                                }
                            }
                        }];
                    };
                    myChartB.setOption(optionB);
                    //主机2压力环END

                }else{
                    //console.log("zhu_ji2 is none");
                }
                //======主机2END======
                
                //======风机1START======
                if(typeof(result.data.equip[3])!="undefined"){
                    get_key_value(3);
                    $(".fengjiA_workParamsbox").show();
                    //风机1温度环START
                    var myChartC = echarts.init(document.getElementById('ringboxPieC'));
                    var fu_value = -zhengji_temperature;
                    var fengji1_temperature = fu_temperature==1?fu_value:zhengji_temperature;
                    if(fu_temperature==1){
                        var percentC = zhengji_temperature/200;//风机温度百分比计算(-50℃~150℃)
                    }else{
                        var percentC = fengji1_temperature/200;//风机温度百分比计算(-50℃~150℃)
                    }
                    var dataStyle = {
                        normal: {
                            label: {show:false},
                            labelLine: {show:false}
                        }
                    };
                    var optionC = {
                        backgroundColor: 'rgba(0,0,0,0)',
                        title: {
                            //text: (percent * 100) + '%',
                            text: fengji1_temperature,
                            subtext: '℃',
                            x: 'center',
                            y: '26%',
                            textStyle: {
                                color: '#596679',
                                fontSize: 18,
                                fontWeight: 'normal'
                            },
                            subtextStyle: {
                                color: '#666',
                                fontSize: 12
                            }
                        },

                        series : [

                            {
                                name: 'main',
                                type: 'pie',
                                radius: [29, 39],
                                hoverAnimation: false,
                                label: {
                                    normal: {
                                        show: false
                                    }
                                },

                                data: getDataC()
                            }

                        ]
                    };

                    function getDataC() {
                        return [{
                            value: percentC,
                            itemStyle:{
                                normal:{
                                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: '#7388d7'
                                    }, {
                                        offset: 1,
                                        color: '#d12977'
                                    }])
                                }
                            }
                        }, {
                            value: 1 - percentC,
                            itemStyle: {
                                normal: {
                                    color: 'transparent'
                                }
                            }
                        }];
                    };
                    myChartC.setOption(optionC);
                    //风机1温度环END

                }else{
                    //console.log("feng_ji1 is none");
                }
                //======风机1END======

                //======风机2START======
                if(typeof(result.data.equip[4])!="undefined"){
                    get_key_value(4);
                    $(".fengjiB_workParamsbox").show();
                    //风机2温度环START
                    var myChartD = echarts.init(document.getElementById('ringboxPieD'));
                    var fu_value = -zhengji_temperature;
                    var fengji2_temperature = fu_temperature==1?fu_value:zhengji_temperature;
                    if(fu_temperature==1){
                        var percentD = zhengji_temperature/200;//风机温度百分比计算(-50℃~150℃)
                    }else{
                        var percentD = fengji2_temperature/200;//风机温度百分比计算(-50℃~150℃)
                    }
                    
                    var dataStyle = {
                        normal: {
                            label: {show:false},
                            labelLine: {show:false}
                        }
                    };

                    var optionD = {
                        backgroundColor: 'rgba(0,0,0,0)',
                        title: {
                            //text: (percent * 100) + '%',
                            text: fengji2_temperature,
                            subtext: '℃',
                            x: 'center',
                            y: '26%',
                            textStyle: {
                                color: '#596679',
                                fontSize: 18,
                                fontWeight: 'normal'
                            },
                            subtextStyle: {
                                color: '#666',
                                fontSize: 12
                            }
                        },

                        series : [

                            {
                                name: 'main',
                                type: 'pie',
                                radius: [29, 39],
                                hoverAnimation: false,
                                label: {
                                    normal: {
                                        show: false
                                    }
                                },

                                data: getDataD()
                            }

                        ]
                    };

                    function getDataD() {
                        return [{
                            value: percentD,
                            itemStyle:{
                                normal:{
                                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: '#7388d7'
                                    }, {
                                        offset: 1,
                                        color: '#d12977'
                                    }])
                                }
                            }
                        }, {
                            value: 1 - percentD,
                            itemStyle: {
                                normal: {
                                    color: 'transparent'
                                }
                            }
                        }];
                    };
                    myChartD.setOption(optionD);
                    //风机2温度环END

                }else{
                    //console.log("feng_ji2 is none");
                }
                //======风机2END======

                                
            }else{
                $.flytip(result.msg);
            } 

            
        } 
    });    
}
getWorkingParams();
//================================================================
//====================获取设备运行参数END=========================

//======================================================================
//====================设备详情-获取事件视图START========================
$(".MachineDetailsEventstatus a").click(function(){
    $(this).addClass("cur").siblings(".cur").removeClass("cur");
})
var getEventQuickView = function(){
    var is_read = $(".MachineDetailsEventstatus a.cur").attr("data-id");//处理状态0未读1已读空全部
    var createStartDate = $("#startDate").val();//开始时间
    var createStartEnd = $("#endDate").val();//结束时间
    $.ajax({ 
        type:"post", 
        url:urls.deviceEventClassify, 
        data: {token:token,dtu_id:dtuID,is_read:is_read,createStartDate:createStartDate,createStartEnd:createStartEnd}, 
        dataType: 'json', 
        async : true, 
        success:function(result){
            if(result.code==1){
                var eventQuickViewHtml = '';
                for(var val in result.data){
                    var val = parseInt(val);
                    switch (val)
                    {
                    case 0:
                      eventQuickViewHtml += '<a data-id="'+val+'" href="javascript:;"><li>全部<i>(</i><span>'+result.data[val]+'</span><i>)</i></li></a>';
                      break;
                    case 1:
                      eventQuickViewHtml += '<a data-id="'+val+'" href="javascript:;"><li>保养事件<i>(</i><span>'+result.data[val]+'</span><i>)</i></li></a>';
                      break;
                    case 2:
                      eventQuickViewHtml += '<a data-id="'+val+'" href="javascript:;"><li>预警事件<i>(</i><span>'+result.data[val]+'</span><i>)</i></li></a>';
                      break;
                    case 3:
                      eventQuickViewHtml += '<a data-id="'+val+'" href="javascript:;"><li>报警事件<i>(</i><span>'+result.data[val]+'</span><i>)</i></li></a>';
                      break;
                    case 4:
                      eventQuickViewHtml += '<a data-id="'+val+'" href="javascript:;"><li>其他事件<i>(</i><span>'+result.data[val]+'</span><i>)</i></li></a>';
                      break;
                    case 5:
                      eventQuickViewHtml += '<a data-id="'+val+'" href="javascript:;"><li>隐藏事件<i>(</i><span>'+result.data[val]+'</span><i>)</i></li></a>';
                      break;
                    }
                }
                $(".eventsTabbtns").html(eventQuickViewHtml);
                //每次请求后默认显示第一个分类（全部事件），同时也默认请求第一个事件列别全部的事件
                $(".eventsTabbtns").find("a").eq(0).addClass("cur");
                var event_id = $(".eventsTabbtns").find("a").eq(0).attr("data-id");
                getEventTypesList(event_id);
                //========================如果用户点击了事件类别tab栏,则对应事件类别下事件列表START========================
                $(".eventsTabbtns a").unbind("click").click(function(){
                    $(this).addClass("cur").siblings(".cur").removeClass("cur");
                    var event_id = $(this).attr("data-id");
                    getEventTypesList(event_id);
                })
                //========================如果用户点击了事件类别tab栏,则对应事件类别下事件列表END==========================

            }else{
               $.flytip(result.msg);
            }
            
        } 
    });
}
getEventQuickView();
$("#timerfilterBtn").on("click",function(){
    getEventQuickView();
})
//======================================================================
//====================设备详情-获取事件视图END==========================

//=========================================================================================================
//====================设备详情-获取事件视图下面每一个TAB栏下对应事件类别的事件START========================
//加载对应事件类别下的事件--获取事件列表
var getEventTypesList = function(event_id){
    var dtu_id = dtuID;//控制器id
    var customer_name="";
    var event_type = event_id;//事件类别
    var event_id ="";
    var is_read = $(".MachineDetailsEventstatus a.cur").attr("data-id");//处理状态
    var createStartDate = $("#startDate").val();//开始时间
    var createStartEnd = $("#endDate").val();//结束时间
    var pageNow = 1;
    var pageSize = 1000;
    $.vloading.show();
    $.ajax({ 
        type:"post", 
        url:urls.eventLists, 
        data: {token:token,dtu_id:dtuID,customer_name:customer_name,event_type:event_type,event_id:event_id,is_read:is_read,createStartDate:createStartDate,createStartEnd:createStartEnd,pageNow:pageNow,pageSize:pageSize}, 
        dataType: 'json', 
        async : true,
        success:function(result){
            $.vloading.remove();
            if(result.code==1){
                if(result.data.records.length>0){
                    var showTypesEventsHtml = '';
                    for(var i=0,j=result.data.records.length;i<j;i++){
                        if(result.data.records[i].is_read==0){//事件未读
                            showTypesEventsHtml +='<a data-attachInfo="'+result.data.records[i].attach_info+'"  data-id="'+result.data.records[i].id+'" data-eventTime="'+result.data.records[i].create_date+'" data-isRead="'+result.data.records[i].is_read+'" class="swiper-slide rela" href="javascript:;"><li class="rela"><h3>'+result.data.records[i].event_name+'</h3><h4 class="nosee">'+result.data.records[i].event_reason+'</h4><p><span>'+result.data.records[i].create_date+'</span><em class="red">未处理</em></p></li><div class="abso triangle Nodeal"></div><div class="statusIcons abso"><i class="xwl i-Error pdr5"></i></div></a>';
                        }else{//事件已读
                            showTypesEventsHtml +='<a data-attachInfo="'+result.data.records[i].attach_info+'"  data-id="'+result.data.records[i].id+'" data-eventTime="'+result.data.records[i].create_date+'" data-isRead="'+result.data.records[i].is_read+'" class="swiper-slide rela" href="javascript:;"><li class="rela"><h3>'+result.data.records[i].event_name+'</h3><h4 class="nosee">'+result.data.records[i].event_reason+'</h4><p><span>'+result.data.records[i].create_date+'</span><em class="green">已处理</em></p></li><div class="abso triangle dealed"></div><div class="statusIcons abso"><i class="xwl i-yes pdr5"></i></div></a>';
                        }
                    }
                    $(".showTypesEventsHtml").html(showTypesEventsHtml);
                    //swiper
                    var navswiper = new Swiper('.eventsFilterShow .swiper-container', {
                        slidesPerView: 'auto',
                        spaceBetween: 0,
                        freeMode: true,
                        scrollbar: '.swiper-scrollbar',
                        scrollbarHide:true,
                        scrollbarDraggable : true ,
                    });

                    //tochslider bar go zero
                    $(".swiper-wrapper").css("transform","translate3d(0px, 0px, 0px)");
                }else{
                    $(".showTypesEventsHtml").html('<p class="txtc" style="width:100%;padding:19px 0;font-size:14px;">暂无数据</p>');
                    $(".swiper-wrapper").css("transform","translate3d(0px, 0px, 0px)");
                }

            }else{
                $.flytip(result.msg);
            }
        } 
    });    
}

//=========================================================================================================
//====================设备详情-获取事件视图下面每一个TAB栏下对应事件类别的事件END==========================

//=================================================================================================================================================
//====================设备详情-设备历史记录START(点击每一个时间点的事件，即查询历史记录)===========================================================
$("body").on("click",".showTypesEventsHtml a",function(){
    var date = $(this).attr("data-eventTime");
    var is_read = $(this).attr("data-isRead");
    var ids = $(this).attr("data-id");
	var attachInfo = $(this).attr("data-attachInfo");
    var event_name = $(this).find("li").find("h3").html();
    var event_reason = $(this).find("li").find("h4").html();
    getLatestRecording(urls.getPastDevicedetils,date);
    $(this).addClass("cur").siblings().removeClass("cur");
    $(".whatProblems").slideDown(100);
        if(is_read==1){
            $(".dealErrorBtns").html("已处理").css({"color":"#ceccc9","border":"1px solid #ceccc9"});
            $(".event_TypeName").html(event_name).css("color","#78c16e");
            $(".events_Reason").html(attachInfo).css("color","#78c16e");
            $(".whatProblems_lineFGX").css("color","#78c16e");
            return;
        }else{
            $(".dealErrorBtns").html("未处理").css({"color":"#ffbd44","border":"1px solid #ffbd44"}).attr("disabled", false);
            $(".event_TypeName").html(event_name).css("color","#d71e06");
            $(".events_Reason").html(attachInfo).css("color","#d71e06");
            $(".whatProblems_lineFGX").css("color","#d71e06");
            $(".dealErrorBtns").unbind("click").click(function(){  
                $.ajax({ 
                    type:"post", 
                    url:urls.handleEvents, 
                    data: {token:token,ids:ids,is_read:1}, 
                    dataType: 'json', 
                    async : true,
                    success:function(result){ 
                        if(result.code==1){
                            $.flytip(result.msg);
                            var event_id = $(".eventsTabbtns").find("a.cur").attr("data-id");
                            getEventQuickView();
                            $(".eventsTabbtns").find("a.cur").attr("data-id");
                            $(".dealErrorBtns").html("已处理").css({"color":"#ceccc9","border":"1px solid #ceccc9"}).attr("disabled", true);
                            $(".event_TypeName,.events_Reason,.whatProblems_lineFGX").css("color","#78c16e");
                        }else{
                            $.flytip(result.msg);
                        }
                    } 
                });
            })

        }        



})

//=================================================================================================================================================
//====================设备详情-设备历史记录END(点击每一个时间点的事件，即查询历史记录)=============================================================

//================================实时监控START===========================
//========================================================================
var watchingTimer;
var maxWatchingTime=0;
$('.toggle_zd').click(function(e){
  e.preventDefault(); // The flicker is a coding pens thing
  var isConnected = $("#switch_zd").attr("data-isconnected");
  var interval;
  if(isConnected==1){
    $(this).toggleClass('toggle-on');
    if($(this).hasClass("toggle-on")){
        var ctl = 1;
        var maxlongwatch = setInterval(function(){
            maxWatchingTime++;
            if(maxWatchingTime>600){
                var ctl = 2;
                clearInterval(watchingTimer);
                clearInterval(maxlongwatch);
                $(".toggle_zd").removeClass("toggle-on");
            }
        }, 1000);
    }else{
        var ctl = 2;
    }
    $.ajax({ 
        type:"post", 
        url:urls.operateDevicesAllTimeWatch, 
        data: {token:token,dtu_id:dtuID,ctl:ctl}, 
        dataType: 'json', 
        async : true,
        success:function(result){
            if(result.code==1){
                if(ctl==2){
                    clearInterval(watchingTimer);return false;
                }
                watchingTimer = setInterval(function(){
                    getLatestRecording(urls.getNewestDevicedetils);
                    getWorkingParams();
                },4000);
            }else{
                $.flytip(result.msg);
            }}});
    }else{
        $.flytip("当前设备不在线，无法监控");
    }
});
//while close curent page or press F5 see cmd

window.onbeforeunload = function(){ return closePage_stopWatching();}
var closePage_stopWatching = function(){
    //localStorage.setItem("kkmall","sss");
    //localStorage.getItem("kkmall");
	if($("#switch_zd").hasClass("toggle-on")){
		var ctl = 2;$.ajax({ type:"post", url:urls.operateDevicesAllTimeWatch, data: {token:token,dtu_id:dtuID,ctl:ctl}, dataType: 'json', async : true,success:function(result){ $.flytip(result.msg);} 		
		});
	}
}
//window.addEventListener("beforeunload", function(event) {event.returnValue = closePage_stopWatching();});

//========================================================================
//=================================实时监控END============================




//============系统管理模块一级二级三级按钮菜单权限控制 START ============
getOnelayerMenu();
//三级菜单控制显示(设备详情页的二级菜单实际上是一个三级菜单，特殊处理)
$.ajax({ 
    type:"post", 
    url:urls.getMachineBtns, 
    data: {token:localStorage.getItem("token"),id:201}, 
    dataType: 'json', 
    async : true, 
    success:function(result){
        if(result.code==1){
            var tableTopbarlHtml = '';
            for(var i=0;i<result.data.length;i++){
                var forinVals2 = result.data[i].id;
                switch (forinVals2)
                {
                case 205:
                  if(result.data[i].ishide==1){
                    tableTopbarlHtml +='<a href="machineDetails.html?dtuid='+dtuID+'" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
                  }
                  break;
                case 206:
                  if(result.data[i].ishide==1){
                    tableTopbarlHtml +='<a href="'+result.data[i].resKey+'?dtuid='+dtuID+'" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
                  }
                  break;
                case 207:
                  if(result.data[i].ishide==1){
                    tableTopbarlHtml +='<a href="interactiveLog.html?dtuid='+dtuID+'" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
                  }
                  break;
                case 208:
                  if(result.data[i].ishide==1){
                    tableTopbarlHtml +='<a href="#" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
                  }
                  break;
                } 

            }
            $(".mianshowbpt-r").html(tableTopbarlHtml);
            $(".mianshowbpt-r a").eq(0).addClass("cur");
        }else{
            $.flytip(result.msg);
        }
    } 
});    

//============系统管理模块一级二级三级按钮菜单权限控制 END ============

//===刷新/收起START===
$(".refreashedBtns").click(function(){window.location.reload();})
$(".dropupBtn").toggle(
    function(){$(".filterPanelTop_slideUp").slideUp();$(this).find("span").html("展开筛选").siblings("i").addClass("i-sq").removeClass("i-zk");},
    function(){$(".filterPanelTop_slideUp").slideDown();$(this).find("span").html("收起筛选").siblings("i").addClass("i-zk").removeClass("i-sq");}
)
//===刷新/收起END=====
$("#showmyAccountMenu").toggle(
    function(){$("#toggleshowmenu").show();},
    function(){$("#toggleshowmenu").hide();}
);


$(".closeLayerbox").click(function(){
    $(".dituLayerBox,.masking").fadeOut();
})

var myDate = new Date();
$(".refreashedDate").html(myDate.toLocaleString());

//============获取监控和事件处理权限 START============ 2017-06-23 17:07:20 修改 by lc
$.ajax({ 
    type:"post", 
    url:urls.getMachineBtns, 
    data: {token:localStorage.getItem("token"),id:204}, 
    dataType: 'json', 
    async : true, 
    success:function(result){
        if(result.code==1){
            var tableTopbarlHtml = '';
			var arr = '';
            for(var i=0;i<result.data.length;i++){
                arr = result.data[i].id + arr;
            }
			if (arr.indexOf('213') == -1)
			{
				$('.dealErrorBtns').css('display', 'none');
			}
			if (arr.indexOf('214') == -1)
			{
				$('.switch_zd_Villas').css('display', 'none');
			}
        }else{
            $.flytip(result.msg);
        }
    } 
});    
//============获取监控和事件处理权限 END ============
//resq.js END
});

